package hzjbbis.framework.workflow.util.serializer;

import java.text.ParseException;
import java.util.Date;

public class DateSerializer implements Serializer {
	public String serialize(Object object) {
		if (object == null)
			return null;

		String serailized = null;

		if (!(object instanceof Date)) {
			throw new IllegalArgumentException(
				"DateSerializer can't serialize " + object);
		}

		if (object != null) {
			Date date = (Date) object;
			serailized = FormatConstants.DATE_FORMAT.format(date);
		}

		return serailized;
	}

	public Object deserialize(String textValue) {
		if (textValue == null || textValue.trim().length() < 1)
			return null;
		try {
			return FormatConstants.DATE_FORMAT.parseObject(textValue);
		} catch (ParseException e) {
			throw new IllegalArgumentException(
				"DateSerializer can't deserialize " + textValue);
		}

	}

}
